package com.qf.test;

import com.qf.proxy.CglibProxy;
import com.qf.proxy.JDKProxy;
import com.qf.proxy.StaticProxyUserService;
import com.qf.service.GoodService;
import com.qf.service.UserService;
import com.qf.service.impl.GoodServiceImpl;
import com.qf.service.impl.UserServiceImpl;
import org.junit.Test;

public class Demo1 {

    @Test
    public void staticSave(){
        StaticProxyUserService userService = new StaticProxyUserService();

        userService.save();
    }


    @Test
    public void JDKProxyTest(){
        // JDK动态代理是通过当前类的父接口获取到的代理对象,
        /*UserService userService = (UserService) new JDKProxy(new UserServiceImpl()).getProxyInstance();

        userService.save();*/
        GoodServiceImpl goodService = (GoodServiceImpl) new JDKProxy(new GoodServiceImpl()).getProxyInstance();

        goodService.update();
    }

    @Test
    public void cglibProxy(){
        GoodServiceImpl goodService = (GoodServiceImpl) new CglibProxy(new GoodServiceImpl()).getProxyInstance();
        goodService.update();
    }
}
